package com.afd.ozblip.activity;

import com.afd.ozblip.entity.RecDishEntity;
import com.afd.ozblip.image.LoadImage;
import com.afd.ozblip.util.Constants;
import com.afd.ozblip.util.StringUtil;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RatingBar;
import android.widget.TextView;

public class RecommendDishDetailActivity extends BaseActivity {

	/****************** 视图变量 **************************/
	private LinearLayout uploadDishLayout;
	private TextView topTitleTv;
	private ImageView recDishImageIv;
	private TextView recDishNameTv;
	private TextView recDishPriceTv;
	private RatingBar recDishStarRb;
	private TextView recUserNameTv;
	private TextView recUploadTimeTv;

	/****************** 数据变量 **************************/
	private RecDishEntity recDishInfo;
	private LoadImage loadImage;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.recommend_dish_detail);
		// 启动返回功能
		toBack();
		// 寻找视图
		findViews();
		// 设置监听
		setListeners();
		// 获取参数
		getBundle();
		// 设置视图
		setViews();
	}

	/**
	 * 寻找视图
	 */
	public void findViews() {
		this.loadImage = new LoadImage(RecommendDishDetailActivity.this);
		this.uploadDishLayout = (LinearLayout) findViewById(R.id.ll_upload_dish);
		this.topTitleTv = (TextView) findViewById(R.id.tv_business_recommend_topTitle);
		this.recDishImageIv = (ImageView) findViewById(R.id.iv_business_recommend_image);
		this.recDishNameTv = (TextView) findViewById(R.id.tv_business_recommend_dishName);
		this.recDishPriceTv = (TextView) findViewById(R.id.tv_business_recommend_dishPrice);
		this.recDishStarRb = (RatingBar) findViewById(R.id.rb_business_recommend_dishStar);
		this.recUserNameTv = (TextView) findViewById(R.id.tv_business_recommend_userName);
		this.recUploadTimeTv = (TextView) findViewById(R.id.tv_business_recommend_uploadTime);
	}

	/**
	 * 设置监听
	 */
	public void setListeners() {
		View.OnClickListener dishDetailClick = new View.OnClickListener() {

			@Override
			public void onClick(View v) {
				switch (v.getId()) {
				case R.id.ll_upload_dish:
					Intent settingIntent = new Intent(RecommendDishDetailActivity.this,
							UploadPhotoActivity.class);
					startActivity(settingIntent);
					break;

				default:
					break;
				}
			}
		};
		this.uploadDishLayout.setOnClickListener(dishDetailClick);
	}

	/**
	 * 获取传递的参数
	 */
	private void getBundle() {
		Intent intent = getIntent();
		recDishInfo = (RecDishEntity) intent
				.getSerializableExtra("recDishInfo");
	}

	/**
	 * 设置视图
	 */
	private void setViews() {
		if (recDishInfo != null) {
			this.topTitleTv.setText(recDishInfo.getBusinessName());
			String dishImageUrl = recDishInfo.getRecDishSmallImageUrl();
			if(!StringUtil.isNullOrEmpty(dishImageUrl)){
				loadImage.addTask(Constants.WEB_PATH+dishImageUrl, recDishImageIv);
			}
			this.recDishNameTv.setText(recDishInfo.getDishName());
			this.recDishPriceTv.setText(recDishInfo.getDishPrice());
			this.recUserNameTv.setText(recDishInfo.getRecUserName());
			this.recDishStarRb.setRating(recDishInfo.getRecStar());
			this.recUploadTimeTv.setText(recDishInfo.getRecTime());
		}
	}
}